package com.example.myapplication;

import android.annotation.SuppressLint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;

public class Stu_list extends AppCompatActivity {
    private RecyclerView recyclerView;
    private StudentAdapter studentAdapter;
    private ArrayList<Student>studentArrayList=new ArrayList<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_stu_list);

        recyclerView=findViewById(R.id.students_List);
        studentAdapter=new StudentAdapter(studentArrayList);
        recyclerView.setAdapter(studentAdapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(Stu_list.this));
        getDataFromBmob();

    }
//将后端云数据传到列表上
    private void getDataFromBmob() {
        BmobQuery<Student>studentBmobQuery=new BmobQuery<>();
        studentBmobQuery.findObjects(new FindListener<Student>() {
            @Override
            public void done(List<Student> list, BmobException e) {
                if (e==null){
                    studentArrayList.addAll(list);
                    studentAdapter.notifyDataSetChanged();
                }
            }
        });

    }
}
